package com.bat.spring.beanlifecycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component("person")
public class Person implements BeanNameAware, BeanFactoryAware, ApplicationContextAware, InitializingBean, DisposableBean {
    private String name;

    public Person() {
        System.out.println("调用Person构造器");
    }

    public void setName(String name) {
        this.name = name;
        System.out.println("调用set方法");
    }

    public void myInit(){
        System.out.println("调用myInit方法");
    }

    public void myDestroy(){
        System.out.println("调用myDestroy方法");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("调用setBeanFactory方法");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("调用setBeanName方法");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("调用destroy方法");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("调用afterPropertiesSet方法");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("调用setApplicationContext方法");
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

